package com.mmall.common;

import java.util.Set;


import com.google.common.collect.Sets;

//存储一些常量名称
public class Const {
	
	//当前用户
	public static final String CURRENT_USER = "currentUser";
	//邮箱
    public static final String EMAIL = "email";
    //用户名
    public static final String USERNAME = "username";
	
    //订单排序方法常量名称的接口
    public interface ProductListOrderBy{
    	
    	//sets是谷歌的guava库中的类
    	//用一个set存放升序和降序排列的常量名称
    	//用set存放不用list存放是因为set存放寻找时的时间复杂度为O(1),list为O(n)
    	Set<String> PRICE_ASC_DESC=Sets.newHashSet("price_desc","price_asc");
    	
    }
    
    //购物车模块常量名称的接口
    public interface Cart{
        int CHECKED = 1;//即购物车选中状态
        int UN_CHECKED = 0;//购物车中未选中状态

        //限制购物车指当购物车中数量即将大于仓库实际库存的数量时，限制购物车数量为实际库存的数量
        String LIMIT_NUM_FAIL = "LIMIT_NUM_FAIL";//限制失败
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";//限制成功
    }

    //角色常量名称的接口
    public interface Role{
        int ROLE_CUSTOMER = 0; //普通用户
        int ROLE_ADMIN = 1;//管理员
    }
    
    //商品常量名称的接口
    public enum ProductStatusEnum{
        ON_SALE(1,"在线"),
    	UNDERCARRIAGE(0,"下架");
        private String value;
        private int code;
        ProductStatusEnum(int code,String value){
            this.code = code;
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }

    //订单状态常量名称的接口
    public enum OrderStatusEnum{
        CANCELED(0,"已取消"),
        NO_PAY(10,"未支付"),
        PAID(20,"已付款"),
        SHIPPED(40,"已发货"),
        ORDER_SUCCESS(50,"订单完成"),
        ORDER_CLOSE(60,"订单关闭");


        OrderStatusEnum(int code,String value){
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }

        //用于查询状态码代表含义的方法,识别传递过来的状态码含义	
        public static OrderStatusEnum codeOf(int code){
        	
            for(OrderStatusEnum orderStatusEnum : values()){
                if(orderStatusEnum.getCode() == code){
                    return orderStatusEnum;
                }
            }
            //没有对应状态码时抛出异常
            throw new RuntimeException("没有有找到对应的枚举");
        }
    }
    
  //支付宝回调常量名称的接口
    public interface  AlipayCallback{
    	//前缀TRADE代表的是支付宝支付状态，RESPONSE代表订单是否成功完成支付
    	//等待付款
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        //付款成功
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";
        //订单完成支付
        String RESPONSE_SUCCESS = "success";
        //订单没有完成支付
        String RESPONSE_FAILED = "failed";
    }


    //支付方式常量名称的接口
    public enum PayPlatformEnum{
        ALIPAY(1,"支付宝");

        PayPlatformEnum(int code,String value){
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }
    
    //支付类型常量名称的接口
    public enum PaymentTypeEnum{
        ONLINE_PAY(1,"在线支付");

        PaymentTypeEnum(int code,String value){
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }


        public static PaymentTypeEnum codeOf(int code){
            for(PaymentTypeEnum paymentTypeEnum : values()){
                if(paymentTypeEnum.getCode() == code){
                    return paymentTypeEnum;
                }
            }
            throw new RuntimeException("没有有找到对应的枚举");
        }

    }
}
